<?php

/*
 * This file is part of the Geek-Zoo Projects.
 *
 * @copyright (c) 2010 Geek-Zoo Projects More info http://www.geek-zoo.com
 * @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License
 * @author xuanyan <xuanyan@geek-zoo.com>
 *
 */


require_once ROOT_PATH.'/Abstract/front_abstract.php';

class Action extends front_abstract
{
    function index()
    {
        $t = _GET('t', 0);
		if ($this->weibo_info['id']) {
			$sql = "WHERE account_id = {$this->weibo_info['id']}";
	        if ($t == 1) {
	            $sql .= " AND sent_time > 0";
	        } elseif ($t == 2) {
	            $sql .= " AND sent_time = 0";
	        }
	        $sql .= ' LIMIT 50';
	        $data = _model('tweet_list')->getList($sql);
			$this->smarty->assign('data', $data);
		}
        $this->smarty->display('history.html');
    }

    function delete()
    {
        if ($id = _GET('id', 0)) {
            _model('tweet_list')->delete(array('account_id'=>$this->weibo_info['id'], 'id' => $id));
        }
        $this->redirect('history.html');
    }

	function send()
	{
		if ($id = _GET('id', 0)) {
			$info = _model('tweet_list')->read(array('account_id'=>$this->weibo_info['id'], 'id' => $id));
			$api = new ApiSina();
			$api->update($this->oauth_token, $this->oauth_token_secret, $info['content'], $info['pic']);
            _model('tweet_list')->delete(array('account_id'=>$this->weibo_info['id'], 'id' => $id));
	        $this->redirect('history.html');
        }
	}
}

?>